package com.stoken.web.control;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.stoken.domain.MemberBaseInfo;
import com.stoken.domain.MemberLeaveMessage;
import com.stoken.domain.Notice;
import com.stoken.domain.TravelLeaveMessage;
import com.stoken.service.MemberBaseInfoService;
import com.stoken.service.MemberLeaveMessageService;
import com.stoken.service.NoticeService;
import com.stoken.service.TravelLeaveMessageService;
import com.stoken.web.StokenUtils;
import com.symbio.commons.Compositor;
import com.symbio.commons.Page;
import com.symbio.commons.Compositor.CompositorType;

@Controller
@RequestMapping("/index")
public class IndexControl {
	
	@Autowired
	private MemberBaseInfoService mbBaseInfoService;
	
	@Autowired
	private NoticeService noticeService;
	
	@Autowired
	private MemberLeaveMessageService memberLeaveMessageService;
	
	@Autowired
	private TravelLeaveMessageService travelLeaveMessageService;
	
	@RequestMapping("/main")
	public String loadIndex(HttpServletRequest request){
		
		MemberBaseInfo mbi = (MemberBaseInfo)request.getSession().getAttribute(StokenUtils.LOGINACCOUNT);
		//查询公告
	    Page<Notice> noticePage = new Page<Notice>();
	    noticePage.getPagination().setPageSize(8);
		Compositor compositor = new Compositor("createTime",CompositorType.DESC);
		noticePage.setCompositor(compositor);
		noticePage = noticeService.find(noticePage);
		request.setAttribute("noticePage", noticePage);
		
		//查询留言
		Page<MemberLeaveMessage> leavePage = new Page<MemberLeaveMessage>();
		leavePage.getPagination().setPageSize(8);
		compositor = new Compositor("leaveTime",CompositorType.DESC);
		leavePage.setCompositor(compositor);
		leavePage = memberLeaveMessageService.find(leavePage,mbi.getId());	
		request.setAttribute("leavePage", leavePage);
		
		//查询旅游留言
		Page<TravelLeaveMessage> travelPage = new Page<TravelLeaveMessage>();
		compositor = new Compositor("leaveTime",CompositorType.DESC);
		travelPage.setCompositor(compositor);
		travelPage = travelLeaveMessageService.find(travelPage,mbi.getId());
		request.setAttribute("travelPage", travelPage);
		
		return "/index";
	}
}
